# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 16:41:00 2020
齐次基准点旋转缩放
@author: wangshuo
"""

import matplotlib.pyplot as plt
import numpy as np
from math import *

plt.axis([-10,150,100,-10])
plt.axis('on')
plt.grid(True)

p0=np.mat([0,0,1]).T
p1=np.mat([60,0,1]).T
p2=np.mat([60,60,1]).T

p_x=[p0[0,0],p1[0,0],p2[0,0],p0[0,0]]
p_y=[p0[1,0],p1[1,0],p2[1,0],p0[1,0]]

plt.plot(p_x,p_y,color='g')

'''
旋转矩阵
'''
theta=pi/3
r_axis_x=10
r_axis_y=12
plt.scatter(r_axis_x,r_axis_y,c="b")


#t_rotate=np.mat([[cos(theta),-sin(theta),0],[sin(theta),cos(theta),0],[0,0,1]])

t_rotate=np.mat([
                  [cos(theta),-sin(theta),r_axis_x*(1-cos(theta))+r_axis_y*sin(theta)],
                  [sin(theta),cos(theta),r_axis_y*(1-cos(theta))+r_axis_x*sin(theta)],
                  [0,0,1]
                  ])

p0_rotate=np.dot(t_rotate,p0)
p1_rotate=np.dot(t_rotate,p1)
p2_rotate=np.dot(t_rotate,p2)

p_x_rotate=[p0_rotate[0,0],p1_rotate[0,0],p2_rotate[0,0],p0_rotate[0,0]]
p_y_rotate=[p0_rotate[1,0],p1_rotate[1,0],p2_rotate[1,0],p0_rotate[1,0]]

plt.plot(p_x_rotate,p_y_rotate,color='b')


'''
缩放矩阵
'''
scale_x=0.6
scale_y=0.6
s_rpt_x=40
s_rpt_y=20
plt.scatter(s_rpt_x,s_rpt_y,c="r")

t_scale=np.mat([
                  [scale_x,0,s_rpt_x*(1-scale_x)],
                  [0,scale_y,s_rpt_y*(1-scale_y)],
                  [0,0,1]
                  ])
p0_scale=np.dot(t_scale,p0)
p1_scale=np.dot(t_scale,p1)
p2_scale=np.dot(t_scale,p2)

p_x_scale=[p0_scale[0,0],p1_scale[0,0],p2_scale[0,0],p0_scale[0,0]]
p_y_scale=[p0_scale[1,0],p1_scale[1,0],p2_scale[1,0],p0_scale[1,0]]

plt.plot(p_x_scale,p_y_scale,color='r')



plt.show()



